IF EXISTS (SELECT [name] FROM dbo.sysobjects WHERE id = Object_id('[dbo].[row_count]'))
BEGIN
	DROP FUNCTION [dbo].[row_count] 
END
GO 
CREATE FUNCTION dbo.row_count (@table_name sysname) 
-- @table_name we want to get count 
RETURNS bigint 
AS 
BEGIN 
	DECLARE @nn bigint -- number of rows 
	IF @table_name IS NOT NULL
	BEGIN
		SELECT @nn = sum( p.rows ) 
		FROM sys.partitions p
		LEFT JOIN sys.allocation_units a ON p.partition_id = a.container_id 
		WHERE 
		p.index_id in(0,1) 
		and p.rows is not null 
		and a.type = 1 
		and p.object_id = object_id(@table_name) 
	END 
	RETURN (@nn) 
END 
GO
--select dbo.row_count ('BuyersinfoR')